# -*- coding: utf-8 -*-
new Ext.data.Store({
    id : 'store_${componentId}',
    autoLoad : ${str(autoLoad).lower()},
	proxy: new Ext.data.HttpProxy({url: '${url}'}),
	reader : ${ reader.display(value_for(reader), **args_for(reader)) },	
	remoteSort: false,
	newRecordUrl : '${newRecordUrl}',
	%if sortInfo!=None:
	sortInfo : {field:'${sortInfo.field}', direction:'${sortInfo.direction}'},
	%endif
	handleAdd : function(grid ){
			    cb = {store: this,grid : grid, success: this.handleSuccess, failure: this.handleFailure}
			    Ext.lib.Ajax.request('GET', this.newRecordUrl, cb);
		},
		
	handleSuccess : function(response, options){
		 var encResponse = Ext.util.JSON.encode(response.responseText);
		 var jsonData = Ext.util.JSON.decode(encResponse);
		 jsonData = Ext.util.JSON.decode(jsonData);
		 var r = new Ext.data.Record(jsonData.result[0]);
		 this.grid.stopEditing();
		 this.store.add(r);
		 var p = this.store.indexOf(r);
		 this.grid.startEditing(p, 0);
	},
	
	handleFailure : function(response, options){
	}
})